<?php
/**
 * +--------------------------------------------------------+
 * @Created by Phpstorm.
 * @Category NameRule.php
 * @Depiction:
 * @Author: hwy
 * @Date: 2021/3/15  21:33
 * +--------------------------------------------------------+
 */

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class AlphaNumRule implements Rule
{
    /**
     * 判断验证是否通过
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        return preg_match('/^[a-zA-Z0-9]+$/u', $value);
    }

    /**
     * 获取验证错误信息
     *
     * @return string
     */
    public function message()
    {
        return '用户名必须为字母、数字!';
    }

}
